/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package app.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author DangThanh
 */
@Entity
@Table(name = "Grades", catalog = "MailServerDB", schema = "dbo")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Grades.findAll", query = "SELECT g FROM Grades g"),
    @NamedQuery(name = "Grades.findByGradeId", query = "SELECT g FROM Grades g WHERE g.gradeId = :gradeId"),
    @NamedQuery(name = "Grades.findByGradeName", query = "SELECT g FROM Grades g WHERE g.gradeName = :gradeName"),
    @NamedQuery(name = "Grades.findByGradeDes", query = "SELECT g FROM Grades g WHERE g.gradeDes = :gradeDes"),
    @NamedQuery(name = "Grades.findByYears", query = "SELECT g FROM Grades g WHERE g.years = :years")})
public class Grades implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "grade_id", nullable = false)
    private Integer gradeId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "grade_name", nullable = false, length = 50)
    private String gradeName;
    @Size(max = 255)
    @Column(name = "grade_des", length = 255)
    private String gradeDes;
    @Basic(optional = false)
    @NotNull
    @Column(name = "years", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date years;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "gradeId")
    private List<Users> usersList;
    @JoinColumn(name = "course_id", referencedColumnName = "course_id", nullable = false)
    @ManyToOne(optional = false)
    private Courses courseId;

    public Grades() {
    }

    public Grades(Integer gradeId) {
        this.gradeId = gradeId;
    }

    public Grades(Integer gradeId, String gradeName, Date years) {
        this.gradeId = gradeId;
        this.gradeName = gradeName;
        this.years = years;
    }

    public Integer getGradeId() {
        return gradeId;
    }

    public void setGradeId(Integer gradeId) {
        this.gradeId = gradeId;
    }

    public String getGradeName() {
        return gradeName;
    }

    public void setGradeName(String gradeName) {
        this.gradeName = gradeName;
    }

    public String getGradeDes() {
        return gradeDes;
    }

    public void setGradeDes(String gradeDes) {
        this.gradeDes = gradeDes;
    }

    public Date getYears() {
        return years;
    }

    public void setYears(Date years) {
        this.years = years;
    }

    @XmlTransient
    public List<Users> getUsersList() {
        return usersList;
    }

    public void setUsersList(List<Users> usersList) {
        this.usersList = usersList;
    }

    public Courses getCourseId() {
        return courseId;
    }

    public void setCourseId(Courses courseId) {
        this.courseId = courseId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (gradeId != null ? gradeId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Grades)) {
            return false;
        }
        Grades other = (Grades) object;
        if ((this.gradeId == null && other.gradeId != null) || (this.gradeId != null && !this.gradeId.equals(other.gradeId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "app.entity.Grades[ gradeId=" + gradeId + " ]";
    }
}
